<?php
namespace Realisation;

use Model\Process\ProcessBuilderInterface;
use Model\Process\ProcessInterface;

/**
 * Description of ProcessBuilder
 *
 * @author pahhan
 */
class ProcessBuilder extends \Pimple implements ProcessBuilderInterface
{
    public function __construct()
    {
        $app = $this->getApp();
        $values = array(
            'it_happens' => function() use ($app) {
                $one_parser = new ItHappens\OneParser();
                $parser = new ItHappens\Parser($one_parser);
                $loader = new \Model\Loader\BaseLoader();
                $saver = new \Model\Saver\DoctrineDbalSaver($app['db']);
                $process = new BaseProcess($loader, $saver, $parser);

                $saver->setLogger($app['monolog']);
                $process->setLogger($app['monolog']);
                return $process;
            },
            'bash' => function() use ($app) {
                $one_parser = new Bash\OneParser();
                $parser = new  Bash\Parser($one_parser);
                $loader = new \Model\Loader\BaseLoader();
                $saver = new \Model\Saver\DoctrineDbalSaver($app['db']);
                $process = new BaseProcess($loader, $saver, $parser);

                $saver->setLogger($app['monolog']);
                $process->setLogger($app['monolog']);
                return $process;
            },
            'zadolbali' => function() use ($app) {
                $one_parser = new Zadolbali\OneParser();
                $parser = new  Zadolbali\Parser($one_parser);
                $loader = new \Model\Loader\BaseLoader();
                $saver = new \Model\Saver\DoctrineDbalSaver($app['db']);
                $process = new BaseProcess($loader, $saver, $parser);

                $saver->setLogger($app['monolog']);
                $process->setLogger($app['monolog']);
                return $process;
            },
        );
        parent::__construct($values);
    }

    /**
     *
     * @return App
     */
    private function getApp()
    {
        return App::getInstance();
    }

    /**
     * @param string $key
     * @return ProcessInterface
     */
    public function build($key)
    {
        return $this->offsetGet($key);

    }    //put your code here
}

